﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Revis.VClinicNet.Core.Domain;
using Revis.VClinicNet.Util.Translation;
using Revis.VClinicNet.Core.Domain.Credentials;
using AutoMapper;

namespace Revis.VClinicNet.App.Internal.Dto.Mappers
{
    public class WorkTimeDtoMapper : IDtoMapper
    {
        public static Func<Doctor, string> Name = (d) => {
            return d.FirstName + " " + d.Surname;
        };        

        public static Func<WorkTime, string> BeginInfo = (w) => {
            if (w.IsWorking == false) {
                return new DateTime().ToShortTimeString();
            }
            return w.BeginTime.DateTime().ToShortTimeString();
        };

        public static Func<WorkTime, string> EndInfo = (w) => {
            if (w.IsWorking == false) {
                return new DateTime().ToShortTimeString();
            }
            return w.EndTime.DateTime().ToShortTimeString();
        };

        public void Map()
        {
            Mapper.CreateMap<WorkTime, WorkTimeDto>()
                .ForMember(wt => wt.BeginHour, mo => mo.MapFrom(wt => wt.BeginTime.Hour))
                .ForMember(wt => wt.BeginMinute, mo => mo.MapFrom(wt => wt.BeginTime.Minute))
                .ForMember(wt => wt.EndHour, mo => mo.MapFrom(wt => wt.EndTime.Hour))
                .ForMember(wt => wt.EndMinute, mo => mo.MapFrom(wt => wt.EndTime.Minute));

            Mapper.CreateMap<WorkTime, WorkTimeInfoDto>()
                .ForMember(wt => wt.BeginInfo, mo => mo.MapFrom(wt => BeginInfo(wt)))
                .ForMember(wt => wt.EndInfo, mo => mo.MapFrom(wt => EndInfo(wt)));

            Mapper.CreateMap<WorkTime, WorkTimeRoomInfoDto>()
                .ForMember(wt => wt.BeginInfo, mo => mo.MapFrom(wt => BeginInfo(wt)))
                .ForMember(wt => wt.EndInfo, mo => mo.MapFrom(wt => EndInfo(wt)));
        }
    }
}
